package dt.board.qna;

import com.opensymphony.xwork2.ActionSupport;
import com.ibatis.common.resources.Resources;
import com.ibatis.sqlmap.client.SqlMapClient;
import com.ibatis.sqlmap.client.SqlMapClientBuilder;

import dt.member.memberVO;

import java.io.Reader;
import java.io.IOException;
import java.util.Map;

import org.apache.struts2.interceptor.SessionAware;



public class qnaViewAction extends ActionSupport implements SessionAware{
	private Map session;
	public static Reader reader;
	public static SqlMapClient sqlMapper;
	
	private qnaBoardVO paramClass = new qnaBoardVO();
	private qnaBoardVO resultClass = new qnaBoardVO();
	

	
	private int currentPage;
	private int no;
	private String password;
	
	private int adminCheck; //더미 아이디 설정
	private String adminId; 
	private int BoardFlag = 4;

	

	
	public qnaViewAction() throws IOException
	{
		reader = Resources.getResourceAsReader("sqlMapConfig.xml");
		sqlMapper = SqlMapClientBuilder.buildSqlMapClient(reader);
		reader.close();
	}

	public String execute() throws Exception {
		paramClass.setNo(getNo());
		sqlMapper.update("qna.updateReadHit",paramClass);
		
		resultClass = (qnaBoardVO) sqlMapper.queryForObject("qna.selectOne", getNo());
		
		if(session.get("id") != null){
			
			
		     if(session.get("id").equals("admin1")){
			
		            	adminCheck = 1;
			
		}
	}
		
	    return SUCCESS;
	}
	

	
	public String checkForm() throws Exception
	{
		return SUCCESS;
	}
	
	public String checkAction()	throws Exception
	{
		paramClass.setNo(getNo());
		paramClass.setPassword(getPassword());
		
		resultClass = (qnaBoardVO) sqlMapper.queryForObject("qna.selectPassword", paramClass);
		
		if(resultClass == null)
			return ERROR;
		
		return SUCCESS;
	}
	
	public String adminCheckAction() throws Exception{
		
	    if(session.get("id").equals("admin1") && getPassword().equals("delete")){
	    	
	    	return SUCCESS;
	    	
	    }else{
	    	
	    	return ERROR;
	    }
		
		
	}
	




	public qnaBoardVO getParamClass() {
		return paramClass;
	}

	public void setParamClass(qnaBoardVO paramClass) {
		this.paramClass = paramClass;
	}

	public qnaBoardVO getResultClass() {
		return resultClass;
	}

	public void setResultClass(qnaBoardVO resultClass) {
		this.resultClass = resultClass;
	}

	public int getCurrentPage() {
		return currentPage;
	}

	public void setCurrentPage(int currentPage) {
		this.currentPage = currentPage;
	}

	public int getNo() {
		return no;
	}

	public void setNo(int no) {
		this.no = no;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}



	public Map getSession() {
		return session;
	}

	public void setSession(Map session) {
		this.session = session;
	}

	public int getAdminCheck() {
		return adminCheck;
	}

	public void setAdminCheck(int adminCheck) {
		this.adminCheck = adminCheck;
	}

	public String getAdminId() {
		return adminId;
	}

	public void setAdminId(String adminId) {
		this.adminId = adminId;
	}

	public int getBoardFlag() {
		return BoardFlag;
	}

	public void setBoardFlag(int boardFlag) {
		BoardFlag = boardFlag;
	}




}
